Skip to content

Note

Click here to download the full example code

Plot pulsed simulation

This example demonstrates how to execute a pulsed simulation using ndk

import neurotechdevkit as ndk

scenario = ndk.make("scenario-0-v0")
result = scenario.simulate_pulse()
result.render_pulsed_simulation_animation()

Out:

/Users/newtonsander/workspace/bci/neurotechdevkit/.venv/lib/python3.9/site-packages/pkg_resources/__init__.py:121: DeprecationWarning: pkg_resources is deprecated as an API
  warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)
/Users/newtonsander/workspace/bci/neurotechdevkit/.venv/lib/python3.9/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('mpl_toolkits')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  declare_namespace(pkg)
/Users/newtonsander/workspace/bci/neurotechdevkit/.venv/lib/python3.9/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('sphinxcontrib')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  declare_namespace(pkg)
creating a grid with shape: (101, 81) for extent: [0.05 0.04] m
Memory and time requirement estimations do not currently support pulsed simulations, so none will be provided.
Default Devito configuration:
         * autotuning=off
         * develop-mode=False
         * mpi=False
         * log-level=DEBUG
         * language=openmp
(ShotID 0) Preparing to run state for shot
(ShotID 0) Estimated bandwidth for the propagated wavelet 0.257-0.724 MHz
(ShotID 0) Spatial grid spacing (0.500 mm | 4.145 PPW) is higher than dispersion limit (0.415 mm | 5.000 PPW)
(ShotID 0) Time grid spacing (0.083 μs | 46%) is above OT2 limit (0.080 μs) and below OT4 limit (0.145 μs)
(ShotID 0) Selected undersampling level 4
(ShotID 0) Selected time stepping scheme OT4
/Users/newtonsander/workspace/bci/neurotechdevkit/.venv/lib/python3.9/site-packages/devito/finite_differences/differentiable.py:224: DeprecationWarning: NotImplemented should not be used in a boolean context
  return super(Differentiable, self).__eq__(other) and\
Operator `acoustic_iso_state` instance configuration:
         * subs={h_x: 0.0005, h_y: 0.0005}
         * opt=advanced
         * platform=None
Operator `acoustic_iso_state` generated in 8.90 s
  * lowering.Clusters: 4.04 s (45.5 %)
     * specializing.Clusters: 2.68 s (30.2 %)
  * lowering.Expressions: 2.80 s (31.5 %)
Flops reduction after symbolic optimization: [3457 --> 892]
Operator `acoustic_iso_state` fetched `/var/folders/57/_b49l46122jgsn1lvw_fffd80000gn/T/devito-jitcache-uid501/32af60b7f39bd102cc72f6e36664b12a4fc0663c.c` in 0.47 s from jit-cache
/Users/newtonsander/workspace/bci/neurotechdevkit/.venv/lib/python3.9/site-packages/numpy/ctypeslib.py:137: DeprecationWarning: 

  `numpy.distutils` is deprecated since NumPy 1.23.0, as a result
  of the deprecation of `distutils` itself. It will be removed for
  Python >= 3.12. For older Python versions it will remain present.
  It is recommended to use `setuptools < 60.0` for those Python versions.
  For more details, see:
    https://numpy.org/devdocs/reference/distutils_status_migration.html 


  from numpy.distutils.misc_util import get_shared_lib_extension
AutoTuner: could not perform any runs
/Users/newtonsander/workspace/bci/neurotechdevkit/src/neurotechdevkit/rendering/_animations.py:118: UserWarning: You passed in an explicit save_count=127 which is being ignored in favor of frames=127.
  anim = FuncAnimation(

Generating a video file

You can also generate a video file of the simulation (which requires ffmpeg installed).

To create and save the video as animation.mp4 in the current folder, all you need is the execute following command:

result.create_video_file("animation.mp4", fps=25, overwrite=True)

Out:

/Users/newtonsander/workspace/bci/neurotechdevkit/src/neurotechdevkit/rendering/_animations.py:118: UserWarning: You passed in an explicit save_count=127 which is being ignored in favor of frames=127.
  anim = FuncAnimation(
Saved to animation.mp4 file.

Total running time of the script: ( 1 minutes 11.453 seconds)

Download Python source code: plot_pulsed_simulation.py

Download Jupyter notebook: plot_pulsed_simulation.ipynb

Gallery generated by mkdocs-gallery